﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.OjbectPool
{
    public class BaseObjectPoolConfig : ICloneable
    {


        public static readonly int DEFAULT_MAX_TOTAL = 8;
        public static readonly int DEFAULT_MAX_IDLE = 8;
        public static readonly int DEFAULT_MIN_IDLE = 0;
        public static readonly long DEFAULT_MAX_WAIT_MILLIS = -1L;

        public static readonly long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS =
                1000L * 60L * 30L;

        public static readonly int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;


        public static readonly Boolean DEFAULT_TEST_ON_CREATE = false;

        public static readonly Boolean DEFAULT_TEST_ON_BORROW = false;


        public static readonly Boolean DEFAULT_TEST_ON_RETURN = false;


        public static readonly Boolean DEFAULT_TEST_WHILE_IDLE = false;


        public static readonly long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;


        public static readonly Boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = true;

        private long maxWaitMillis;

        private long minEvictableIdleTimeMillis;

        private int numTestsPerEvictionRun;
        private Boolean testOnCreate;

        private Boolean testOnBorrow;

        private Boolean testOnReturn;

        private Boolean testWhileIdle;

        private long timeBetweenEvictionRunsMillis;

        private Boolean blockWhenExhausted;

        private int maxTotal;

        private int maxIdle;

        private int minIdle;
        public long MaxWaitMillis
        {
            get { return maxWaitMillis; }
            set { maxWaitMillis = value; }
        }

        public long MinEvictableIdleTimeMillis
        {
            get { return minEvictableIdleTimeMillis; }
            set { minEvictableIdleTimeMillis = value; }
        }

        public int NumTestsPerEvictionRun
        {
            get { return numTestsPerEvictionRun; }
            set { numTestsPerEvictionRun = value; }
        }


        public Boolean TestOnCreate
        {
            get { return testOnCreate; }
            set { testOnCreate = value; }
        }
        public Boolean TestOnBorrow
        {
            get { return testOnBorrow; }
            set { testOnBorrow = value; }
        }
        public Boolean TestOnReturn
        {
            get { return testOnReturn; }
            set { testOnReturn = value; }
        }

        public Boolean TestWhileIdle
        {
            get { return testWhileIdle; }
            set { testWhileIdle = value; }
        }

        public long TimeBetweenEvictionRunsMillis
        {
            get { return timeBetweenEvictionRunsMillis; }
            set { timeBetweenEvictionRunsMillis = value; }
        }
        public Boolean BlockWhenExhausted
        {
            get { return blockWhenExhausted; }
            set { blockWhenExhausted = value; }
        }

        public int MaxTotal
        {
            get { return maxTotal; }
            set { maxTotal = value; }
        }

        public int MaxIdle
        {
            get { return maxIdle; }
            set { maxIdle = value; }
        }

        public int MinIdle
        {
            get { return minIdle; }
            set { minIdle = value; }
        }

        public BaseObjectPoolConfig()
        {
            maxWaitMillis = DEFAULT_MAX_WAIT_MILLIS;
            minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;

            numTestsPerEvictionRun =
               DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
            testOnCreate = DEFAULT_TEST_ON_CREATE;

            testOnBorrow = DEFAULT_TEST_ON_BORROW;

            testOnReturn = DEFAULT_TEST_ON_RETURN;

            testWhileIdle = DEFAULT_TEST_WHILE_IDLE;

            timeBetweenEvictionRunsMillis =
               DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;

            blockWhenExhausted = DEFAULT_BLOCK_WHEN_EXHAUSTED;
            maxTotal = DEFAULT_MAX_TOTAL;

            maxIdle = DEFAULT_MAX_IDLE;

            minIdle = DEFAULT_MIN_IDLE;
        }


        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
